package com.qf.JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @author wangyu
 * @Classname: Queryjdbc
 * @Description: TEST
 * @date 2022-04-04 12:39
 */
public class Queryjdbc {
    public static void main(String[] args) throws Exception {
//        1注册驱动
        Class.forName("com.mysql.jdbc.Driver");
//        2获取链接对象
        String url="jdbc:mysql://localhost:3306/dbtest1?useUnicode=true&characterEncoding=utf8";
        String root="root";
        String pwd="12345";

        Connection connection = DriverManager.getConnection(url,root,pwd);//修改后
//        3 获取执行 sql 语句对象
        Statement statement = connection.createStatement();
//        4 执行语句获取结果
        ResultSet resultSet =  statement.executeQuery("select * from books");
//        5处理结果
        while (resultSet.next()){
            String book_isbn =  resultSet.getString(1);
            String book_name =  resultSet.getString(2);
            String book_nuthor =  resultSet.getString(3);
            System.out.println(book_isbn + "/t" + book_name + "/t" + book_nuthor);
        }
//        System.out.println(resultSet);
//        6释放链接
        resultSet.close();
        statement.close();
        connection.close();
    }
}
